package com.example.agriapp.view.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.agriapp.R;
import com.example.agriapp.model.bean.User;

public class DianPuActivity extends AppCompatActivity {

    private EditText edJianJie;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_dianpu);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        TextView name = findViewById(R.id.userName);
        TextView userPhone = findViewById(R.id.userPhone);
        TextView realNameStatus = findViewById(R.id.realNameStatus);
        edJianJie = findViewById(R.id.edJianJie);
        SharedPreferences jianjie = getSharedPreferences("jianjie", MODE_PRIVATE);
         edJianJie.setText(jianjie.getString("jie", ""));
        User user = (User) getIntent().getSerializableExtra("USER");
        name.setText(user.getUsername());
        userPhone.setText(user.getPhone());
        realNameStatus.setText(user.getRealName());

        findViewById(R.id.iv_back).setOnClickListener( v -> finish());

        edJianJie.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                SharedPreferences jianjie = getSharedPreferences("jianjie", MODE_PRIVATE);
                jianjie.edit().putString( "jie", edJianJie.getText().toString()).apply();
            }
        });
    }
}